struct rfc2231_parameter rfc2231_param;
const char *key, *p, *p2;
string_t *str;
- unsigned int i, j, count, next, next_idx;
+ unsigned int i, j, count, next, next_idx, params_count = 0;
bool ok, broken = FALSE;
const char *prev_replacement_str;
int ret;
t_array_init(&rfc2231_params_arr, 8);
str = t_str_new(64);
while ((ret = rfc822_parse_content_param(ctx, &key, str)) != 0) {
+ if (++params_count > RFC2231_MAX_PARAMS)
+ break;
if (ret < 0) {
/* try to continue anyway.. */
broken = TRUE;
/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "str.h"
#include "rfc822-parser.h"
#include "rfc2231-parser.h"
#include "test-common.h"
run_test("rfc2231 parser invalid encoding", input, sizeof(input)-1, output);
}
+static void test_rfc2231_parser_limits(void)
+{
+ string_t *input = t_str_new(1024);
+
+ test_begin("rfc2231 parser limits");
+ str_append(input, "; ");
+ for (unsigned int i = 0; i < 1100; i++)
+ str_printfa(input, "a%u=b%u; ", i, i);
+ struct rfc822_parser_context parser;
+ const char *const *result;
+ rfc822_parser_init(&parser, str_data(input), str_len(input), NULL);
+ test_assert(rfc2231_parse(&parser, &result) == 0);
+
+ unsigned int count = str_array_length(result);
+ test_assert(count == RFC2231_MAX_PARAMS * 2);
+ for (unsigned int i = 0; i < count; i += 2) {
+ str_truncate(input, 0);
+ str_printfa(input, "a%u", i / 2);
+ test_assert_strcmp_idx(result[i], str_c(input), i);
+
+ str_truncate(input, 0);
+ str_printfa(input, "b%u", i / 2);
+ test_assert_strcmp_idx(result[i + 1], str_c(input), i);
+ }
+ rfc822_parser_deinit(&parser);
+ test_end();
+}
+
int main(void)
{
static void (*const test_functions[])(void) = {
test_rfc2231_parser_encodings,
test_rfc2231_parser_utf8_encoding,
test_rfc2231_parser_multi_encodings,
+ test_rfc2231_parser_limits,
NULL
};
return test_run(test_functions);